/**
 * Created by Administrator on 2017/5/10 0010.
 */
import React from "react";
import Relay from "react-relay";
import ReactKey from "../../../util/ReactKey"
import AddExistStyleModal from "./AddExistStyleModal"
import CalendarModal from "./CalendarModal";
import DetailUploadModal from "./DetailUploadModal";
import AddImgModal from "./AddImgModal";
import {message,Steps} from 'antd';
import SaveOrderMutation from "./mutation/SaveOrderMutation"
import ReactDOM from 'react-dom';
import { hashHistory } from 'react-router';
import DelQiniuFileMutation from "./mutation/DelQiniuFileMutation"
import Util from "../../../util/Util";
import ToLeadExcelModal from "./ToLeadExcelModal"
import './css/create_order_common.css'
import CreactStepOneGms from "./CreactStepOneGms"
import CreactStepOneRaw from "./CreactStepOneRaw"
import CreactStepOneCloth from "./CreactStepOneCloth"
import CreactStepOneYarn from "./CreactStepOneYarn"
import CreactStepOnePrint from "./CreactStepOnePrint"
import CreatOrderTwo from "./CreatOrderTwo"
import CreatOrderThree from "./CreatOrderThree"
const Step = Steps.Step;
import InfoOrderMutation from "../mutation/InfoOrderMutation";
import InfoEnquiryOrderMutation from "../mutation/InfoEnquiryOrderMutation";
import {Button} from "fly";
import AddMaterialModal from "./AddMaterialModal"
/*信息列表*/
import EventManager from "../../../util/EventManager"
export default class Createorder extends React.Component {
    constructor(props) {
        super(props);
        this.state = {
            orderId:"",
            oid:"",
            orderType:"",
            account:"",
            imagechange:false,
            name: this.props.location.state.name,
            orderstep:0,
            enquiryId:""
        };
        this.ispartA = true;
        this.ordertype_num = "1";
        this.instructions = [];
        this.enterpriseId = sessionStorage.getItem('enterpriseId');
        this.serviceType = sessionStorage.getItem('serviceType');
        this.traderName_three = '';
        this.parentId_three = '';
        this.makeType_three = '';
        this.name = this.props.location.state.name;
        this.fromEdit = this.props.location.state.fromEdit;
        this.orderId = '';
        /*第二部：表格数组*/
        this.goodsremark = [];
        /*第三步：上游订单*/
        this.parentId = '';
        this.rmark = '';
        this.instructions = [];
        this.dataSource_require = [
            {type:"quality",title:"质量要求",content:""},
            {type:"package",title:"包装要求",content:""},
            {type:"logistics",title:"物流要求",content:""},
            {type:"payMode",title:"付款方式",content:""},
            {type:"dutyBreak",title:"违约责任",content:""},
            {type:"checkAsk",title:"验收要求",content:""},
        ];
        /*不保存-第一、二步数据*/
        this.goodssty="";
        this.stests="";
        this.account="";
        this.addpartBItem=[];
    }


    componentWillMount() {
        // console.log(this.state.name);
        /*0606修改-若是从编辑按钮跳转来的就发请求绑数据*/
        if(this.fromEdit == "edit"||this.fromEdit == "modify"){
            this.orderId = this.props.location.state.oid;
            this.setState({
                oid:this.props.location.state.oid,
                enquiryId:this.props.location.state.enquiryId
            });
            if(this.props.location.state.enquiryId !='' && this.props.location.state.enquiryId != undefined){
                this.infoEnquiryOrder(this.orderId,this.props.location.state.enquiryId);
            }else{
                this.infoOrder(this.orderId);
            }
        }else if(this.fromEdit == "addMateriel"){//添加物料-->生成采购订单
            this.setState({
                oid:"",
                enquiryId:""
            });
            // this.toLeadExcel(this.props.location.state.goods);
        }else {
            this.setState({
                oid:"",
                enquiryId:""
            });
        }
        switch (this.state.name){
            case 'createordergms':
                this.ordertype_num='1';
                this.ispartA = true;
                return
            case 'createorderraw':
                this.ordertype_num='2';
                this.ispartA = false;
                return
            case 'createordercloth':
                this.ordertype_num='3';
                this.ispartA = false;
                return
            case 'createorderprint':
                this.ordertype_num='4';
                this.ispartA = false;
                return
            case 'createorderyarn':
                this.ordertype_num='5';
                this.ispartA = false;
                return
            case 'entryordergms':
                this.ordertype_num='1';
                this.ispartA = true;
                return
        }
    }
    componentDidMount(){
        if(this.fromEdit != "edit"||this.fromEdit != "modify" || this.fromEdit != "addMateriel"){
            this.refs.stepone.setState({
                goods:[{}, {}, {}]
            })
        }
        if(this.fromEdit == "addMateriel"){//添加物料-->生成采购订单
            this.toLeadExcel(this.props.location.state.goods);
            let {parentId,partAName,account} = this.props.location.state;
            this.refs.stepone.setState({
                parentId: parentId,
                partAName: partAName ? partAName : "",
                account: account ? Number(account/100).toFixed(2) : "",
                isSelect: 1,
                value: parentId,
                defaultValue: parentId,
            },()=>{
                // this.refs.stepone.setcountcallback();
            });
        }

    }
    /*查询订单详情*/
    infoOrder(orderId){
        Relay.Store.commitUpdate(
            new InfoOrderMutation({
                orderId:orderId,
                enId:this.enterpriseId,
                // orderId:"TD20170605150000019815",
            }),
            {
                onFailure: () => {
                    message.error("网络请求失败")
                },
                onSuccess: (response) => {
                    let errorCode = response.infoOrder.infoOrder.errorCode;
                    if (errorCode == 0) {
                        let order = response.infoOrder.infoOrder.order;
                        let goods = order.orderGoodss;
                        this.goodsremark = order.deliverRequests;
                        this.parentId = order.parentId;
                        this.rmark = order.rmark;
                        /*附件*/
                        let contractUrl1 = order.contractUrl1;
                        let contractUrl2 = order.contractUrl2;
                        let contractUrl3 = order.contractUrl3;
                        let contractUrl4 = order.contractUrl4;
                        let contractUrl5 = order.contractUrl5;
                        let contractUrlId1 = order.contractUrlId1;
                        let contractUrlId2 = order.contractUrlId2;
                        let contractUrlId3 = order.contractUrlId3;
                        let contractUrlId4 = order.contractUrlId4;
                        let contractUrlId5 = order.contractUrlId5;
                        /*附件*/
                        if(contractUrl1){
                            let con = contractUrl1.split("?attname=");
                            let name = con[1],
                                fileKey = con[0].split(".com/")[1];
                            this.instructions.push({"name":name,"url":contractUrl1,"fileKey":fileKey,"sid":contractUrlId1})
                        }
                        if(contractUrl2){
                            let con = contractUrl2.split("?attname=");
                            let name = con[1],
                                fileKey = con[0].split(".com/")[1];
                            this.instructions.push({"name":name,"url":contractUrl2,"fileKey":fileKey,"sid":contractUrlId2})
                        }
                        if(contractUrl3){
                            let con = contractUrl3.split("?attname=");
                            let name = con[1],
                                fileKey = con[0].split(".com/")[1];
                            this.instructions.push({"name":name,"url":contractUrl3,"fileKey":fileKey,"sid":contractUrlId3})
                        }
                        if(contractUrl4){
                            let con = contractUrl4.split("?attname=");
                            let name = con[1],
                                fileKey = con[0].split(".com/")[1];
                            this.instructions.push({"name":name,"url":contractUrl4,"fileKey":fileKey,"sid":contractUrlId4})
                        }
                        if(contractUrl5){
                            let con = contractUrl5.split("?attname=");
                            let name = con[1],
                                fileKey = con[0].split(".com/")[1];
                            this.instructions.push({"name":name,"url":contractUrl5,"fileKey":fileKey,"sid":contractUrlId5})
                        }
                        /*成衣订单-input信息*/
                        this.traderName = order.traderName;
                        this.traderUser = order.traderUser;
                        this.traderId = order.traderId;
                        /*第三步-六个要求*/
                        this.dataSource_require[0].content = order.qualityAsk;
                        this.dataSource_require[1].content = order.packageAsk;
                        this.dataSource_require[2].content = order.logisticsAsk;
                        this.dataSource_require[3].content = order.payMode;
                        this.dataSource_require[4].content = order.dutyBreak;
                        this.dataSource_require[5].content = order.checkAsk;
                        this.refs.stepone.setState({
                            goods: goods
                        },()=>{
                            this.refs.stepone.setcountcallback();
                        })
                    } else{
                        if(errorCode == 500){
                            message.error('服务器错误，请联系系统管理员')
                        }
                    }
                }

            }
        );
    }

    /*查询历史订单详情*/
    infoEnquiryOrder(orderId,enquiryId){
        Relay.Store.commitUpdate(
            new InfoEnquiryOrderMutation({
                orderId:orderId,
                enId:this.enterpriseId,
                enquiryId: enquiryId
            }),
            {
                onFailure: () => {
                    message.error("网络请求失败")
                },
                onSuccess: (response) => {
                    let errorCode = response.infoEnquiryOrder.infoEnquiryOrder.errorCode;
                    if (errorCode == 0) {
                        let order = response.infoEnquiryOrder.infoEnquiryOrder.order;
                        let goods = order.orderGoodss;
                        this.goodsremark = order.deliverRequests;
                        this.parentId = order.parentId;
                        this.rmark = order.rmark;
                        this.account = order.account;
                        /*附件*/
                        let contractUrl1 = order.contractUrl1;
                        let contractUrl2 = order.contractUrl2;
                        let contractUrl3 = order.contractUrl3;
                        let contractUrl4 = order.contractUrl4;
                        let contractUrl5 = order.contractUrl5;
                        let contractUrlId1 = order.contractUrlId1;
                        let contractUrlId2 = order.contractUrlId2;
                        let contractUrlId3 = order.contractUrlId3;
                        let contractUrlId4 = order.contractUrlId4;
                        let contractUrlId5 = order.contractUrlId5;
                        /*合同附件*/
                        if(contractUrl1){
                            let con = contractUrl1.split("?attname=");
                            let name = con[1],
                                fileKey = con[0].split(".com/")[1];
                            this.instructions.push({"name":name,"url":contractUrl1,"fileKey":fileKey,"sid":contractUrlId1})
                        }
                        if(contractUrl2){
                            let con = contractUrl2.split("?attname=");
                            let name = con[1],
                                fileKey = con[0].split(".com/")[1];
                            this.instructions.push({"name":name,"url":contractUrl2,"fileKey":fileKey,"sid":contractUrlId2})
                        }
                        if(contractUrl3){
                            let con = contractUrl3.split("?attname=");
                            let name = con[1],
                                fileKey = con[0].split(".com/")[1];
                            this.instructions.push({"name":name,"url":contractUrl3,"fileKey":fileKey,"sid":contractUrlId3})
                        }
                        if(contractUrl4){
                            let con = contractUrl4.split("?attname=");
                            let name = con[1],
                                fileKey = con[0].split(".com/")[1];
                            this.instructions.push({"name":name,"url":contractUrl4,"fileKey":fileKey,"sid":contractUrlId4})
                        }
                        if(contractUrl5){
                            let con = contractUrl5.split("?attname=");
                            let name = con[1],
                                fileKey = con[0].split(".com/")[1];
                            this.instructions.push({"name":name,"url":contractUrl5,"fileKey":fileKey,"sid":contractUrlId5})
                        }
                        /*成衣订单-input信息*/
                        this.traderName = order.traderName;
                        this.traderUser = order.traderUser;
                        this.traderId = order.traderId;
                        /*第三步-六个要求*/
                        this.dataSource_require[0].content = order.orderOthers.qualityAsk;
                        this.dataSource_require[1].content = order.orderOthers.packageAsk;
                        this.dataSource_require[2].content = order.orderOthers.logisticsAsk;
                        this.dataSource_require[3].content = order.orderOthers.payMode;
                        this.dataSource_require[4].content = order.orderOthers.dutyBreak;
                        this.dataSource_require[5].content = order.orderOthers.checkAsk;
                        if (this.serviceType == 6) {
                            this.refs.stepone.setState({
                                goods: goods,
                                traderName: order.traderName,
                                parentId: order.parentId,
                                partAName: order.parentOrder ? order.parentOrder.partBName : null,
                                account: order.parentOrder ? Number(order.parentOrder.account/100).toFixed(2) : null,
                                isSelect: 1,
                                value: order.parentId,
                                makeType: order.makeType,
                                defaultValue: order.makeType,
                            },()=>{
                                this.refs.stepone.setcountcallback();
                            });
                        } else {
                            this.refs.stepone.setState({
                                goods: goods,
                                traderName: order.traderName,
                                parentId: order.parentId,
                                partAName: order.parentOrder ? order.parentOrder.partAName : null,
                                account: order.parentOrder ? Number(order.parentOrder.account/100).toFixed(2) : null,
                                isSelect: 1,
                                value: order.parentId,
                                makeType: order.makeType,
                                defaultValue: order.makeType,
                            },()=>{
                                this.refs.stepone.setcountcallback();
                            });
                        }
                        /*添加乙方数据*/
                        /*let orderOperates = order.orderOperates?order.orderOperates:[];
                        orderOperates.map((item,index)=>{
                            this.addpartBItem.deobj={text:item.toUserName,value:item.toId};
                            this.addpartBItem.enId=item.toId;
                            this.addpartBItem.enName=item.toUserName;
                            this.addpartBItem.isedit=true;
                            this.addpartBItem.name=item.toUserName;
                            this.addpartBItem.phone=item.toUserPhone;
                            this.addpartBItem.toUserId=item.toUserId;
                        });*/
                    } else{
                        if(errorCode == 500){
                            message.error('服务器错误，请联系系统管理员')
                        }
                    }
                }
            }
        );
    }

   componentWillReceiveProps(nextProps){
       if(nextProps.location.state){
           this.fromEdit = nextProps.location.state.fromEdit;
           if(this.fromEdit != "edit"||this.fromEdit != "modify"){
               this.setState({
                   oid:"",
                   enquiryId:""
               })
           }else if(this.fromEdit == "addMateriel"){
               this.setState({
                   oid:"",
                   enquiryId:""
               });
               this.toLeadExcel(this.props.location.state.goods);
           }
           if(nextProps.location.state){
               this.setState({
                   name:nextProps.location.state.name,
                   orderstep:0
               });
               switch (nextProps.location.state.name){
                   case 'createordergms':
                       this.ordertype_num='1';
                       this.ispartA = true;
                       return;
                   case 'createorderraw':
                       this.ordertype_num='2';
                       this.ispartA = false;
                       return;
                   case 'createordercloth':
                       this.ordertype_num='3';
                       this.ispartA = false;
                       return;
                   case 'createorderprint':
                       this.ordertype_num='4';
                       this.ispartA = false;
                       return;
                   case 'createorderyarn':
                       this.ordertype_num='5';
                       this.ispartA = false;
                       return;
                   case 'entryordergms':
                       this.ordertype_num='1';
                       this.ispartA = true;
                       return
               }
           }
       }
   }

    componentWillUnmount(){
        // this.refs.savedata.setState({
        //     visible:true
        // });
        // Modal.confirm({
        //     title: '是否保存数据',
        //     content: 'some descriptions',
        //     onOk() {
        //         console.log('OK');
        //     },
        //     onCancel() {
        //         console.log('Cancel');
        //     },
        // });
    }

    //显示添加图片modal
    showimgmodal(index,url){
        this.refs.addimg.setState({
            visible:true,
            index:index,
            imageUrl:url
        });
    }

    //确认选择图片
    setgoodsimg(url,index){
        // let imageflag = this.state.imagechange
        //
        // this.setState({
        //     imagechange:!imageflag
        // },()=>{
        //
        // });

        this.refs.stepone.setgoodsimg(url,index);



        this.refs.addimg.setState({
            visible:false
        });
    }

    delqiniufile(item, fileKye) {
        Relay.Store.commitUpdate(
            new DelQiniuFileMutation({
                fileKey: fileKye
            }),
            {
                onFailure: () => {

                },
                onSuccess: (response) => {
                    let errorCode = response.delQiniuFile.delQiniuFile.errorCode;
                    if (errorCode == 0) {
                        Util.removedarrayitem(this.instructions, item);
                        this.setState({
                            instructions: this.instructions
                        });
                    }
                }
            }
        )
    }

    addpact(name, hash, url, fileKey,sid) {
      this.refs.stepthree.addpact(name, hash, url, fileKey,sid);
        // this.instructions.push({"name": name, "hash": hash, "url": url, "fileKey": fileKey,"sid":sid});
        // this.refs.stepthree.setState({
        //     instructions: this.instructions
        // });
    }
    //点击添加附件
    addinstructions() {
        if (this.refs.stepthree.instructions.length >= 5) {
            message.info('不能超过5个');
            return
        }
        this.refs.deup.setState({
            visible: true
        });
    }


    //从商品库选择
    ShowLibrary() {
        this.refs.addesm.setState({
            visible: true
        });
    }
    //从商品库选择导入
    addModalfromlist(orders) {
        let orderss = JSON.stringify(orders);
        let obj = JSON.parse(orderss);
        this.refs.stepone.addModalfromlist(obj);
        this.refs.addesm.setState({
            visible: false,
        });
    }


    StepOne(){
        let goods = [];
        let instructions = [];
        let tempArray = [],validate = true,isRequire = true

        this.refs.stepone.state.goods.map((v,i) =>{
          tempArray.push(v.styleNo)
        })

        tempArray.forEach((v, i, ele) => {
          if (v != undefined) {
            ele.indexOf(v) !== i ? validate = false : null
          }
        })
        if (this.state.name == 'createordergms' || this.state.name == 'entryordergms') {
            //成衣订单无必填校验
            if (this.refs.stepone.state.makeType == null) {
                message.config({
                    top: 30,
                })
                message.info('请选择订单类型');
                return;
            }
        } else {
            //选择上游订单为必填项
            if (this.refs.stepone.state.account == '') {
              message.config({
                top: 30,
              })
              message.info('请选择上游订单');
              return;
            }
        }
        // console.log(validate);  //true的时候表示没有出现款号重复
        if (this.state.name == 'createordergms' && !validate) {
          message.info('款号不能相同')
          return
        }
        this.refs.stepone.state.goods.map((context,index)=>{
          if(this.state.name == 'createordergms' || this.state.name == 'entryordergms') { //如果是成衣订单 录入成衣订单
            if (context.quantity && context.quantity != '' && context.styleNo && context.styleNo != '' && context.price && context.price != '') {
              goods.push(context)
            } else if (context.quantity != '' || context.styleNo != '' || context.price != '') {
              if((context.quantity == undefined || context.quantity == '') &&
              (context.styleNo == undefined || context.styleNo == '')&&
              (context.price == undefined || context.price == '')){

              }else{
                isRequire = false
              }

            }
          } else if(this.state.name != 'createordergms'){
            if (context.price && context.price != '' && context.quantity && context.quantity != '') {
              goods.push(context)
            } else if ( context.price != '' || context.quantity != ''){
              if((context.price == undefined || context.price == '') &&
              (context.quantity == undefined || context.quantity == '')){

              } else {
                isRequire = false
              }
            }
          }
        });

        if(goods.length==0 || !isRequire){
            message.info('请完整填写订单数据');
            return;
        }
        // goods[0].price = Number((Number(goods[0].price)).toFixed(2));
        let goodssty = JSON.stringify(goods);
        let createUser = sessionStorage.getItem('uid');
        let account = this.refs.stepone.refs.totalcount.state.totalprice*100;
        this.account = this.refs.stepone.refs.totalcount.state.totalprice*100;
        let traderName = this.refs.stepone.state.traderName;
        let makeType = this.refs.stepone.state.makeType;
        this.makeType_three = this.refs.stepone.state.makeType;
        this.traderName_three = this.refs.stepone.state.traderName;
        let signedContract = this.refs.stepone.state.signedContract;
        this.signedContract_three = this.refs.stepone.state.signedContract;
        let currency = this.refs.stepone.state.currency;
        let partAName = sessionStorage.getItem('enterpriseName');
        let partA = sessionStorage.getItem('enterpriseId');
        let partAUserName = sessionStorage.getItem('username');
        let address = sessionStorage.getItem('address');

        let phone = sessionStorage.getItem('phone');
        let parentId = ''
        if (this.state.name != 'createordergms') {
           parentId = this.refs.stepone.state.parentId;
           this.parentId_three = this.refs.stepone.state.parentId;
        }
        /*制衣厂创建成衣订单或点击修改 - 不发请求*/
        if(this.fromEdit == "entry" || this.fromEdit == "modify"){
            this.goodssty = goodssty;
            this.setState({
                orderstep:1,
            });
        }else {
            Relay.Store.commitUpdate(
                new SaveOrderMutation({
                    parentId: parentId,
                    createUser:createUser,
                    enId:partA,
                    account:account.toFixed(0),
                    payAccount:0,
                    orderType:this.ordertype_num,
                    partA:partA,
                    partAName:partAName,
                    partAUserId:createUser,
                    partAUserName:partAUserName,
                    goodsInfo:goodssty,
                    oid:this.state.oid,
                    partAAddress:address,
                    partAPhone: phone,
                    enquiryId:this.state.enquiryId,
                    traderName: traderName,
                    currency: currency,
                    makeType: makeType
                }),
                {
                    onFailure: () => {
                        message.info('提交失败');
                    },
                    onSuccess: (response) => {
                        let errorCode = response.saveOrder.saveOrder.errorCode;
                        let order = response.saveOrder.saveOrder.order;
                        if(errorCode == 0){
                            this.setState({
                                orderstep:1,
                                oid:order.oid,
                                enquiryId:order.enquiryId
                            });
                        }
                    }
                }
            )
        }
    }
    StepTwo(){
        let goodremark = [];
        this.refs.steptwo.state.goodsremark.map((context,index)=>{
            if(context.deliverDate&&context.amount){
                goodremark.push(context)
            }
        });
        if(goodremark.length==0){
            message.info('请完整填数据');
            return;
        }
        let contracnum = '';
        let stests = JSON.stringify(goodremark);
        let createUser = sessionStorage.getItem('uid');
        let partAName = sessionStorage.getItem('enterpriseName');
        let partA = sessionStorage.getItem('enterpriseId');
        let partAUserName = sessionStorage.getItem('username');

        /*制衣厂创建成衣订单或点击修改 - 不发请求*/
        if(this.fromEdit == "entry" || this.fromEdit == "modify"){
            this.stests=stests;
            this.setState({
                orderstep:2,
            });
        }else {
            Relay.Store.commitUpdate(
                new SaveOrderMutation({
                    createUser:createUser,
                    enId:partA,
                    orderType:this.ordertype_num,
                    deliverRequest:stests,
                    oid:this.state.oid,
                    enquiryId:this.state.enquiryId
                }),
                {
                    onFailure: () => {
                        message.info('创建失败');
                    },
                    onSuccess: (response) => {
                        let errorCode = response.saveOrder.saveOrder.errorCode;
                        let order = response.saveOrder.saveOrder.order;
                        if(errorCode == 0){
                            this.setState({
                                orderstep:2,
                            });
                        }
                    }
                }
            )
        }
    }

    StepThree(){
        let instructions =[];
        this.refs.stepthree.state.instructions.map((context)=>{
            if(context.sid){
                instructions.push(context.sid);
            }else{
                instructions.push('');
            }
        });
        let traderAddress =''
        let traderPhoneToatal ='';
        let traderPhone = '';
        let createUser = sessionStorage.getItem('uid');
        let phone = sessionStorage.getItem('phone');
        let partAName = sessionStorage.getItem('enterpriseName');
        let partA = sessionStorage.getItem('enterpriseId');
        let partAAddress = this.refs.stepone;
        let partAUserName = sessionStorage.getItem('username');
        let address = sessionStorage.getItem('address');
        // let remark = this.refs.stepthree.refs.remarkinput.state.text;
        let remark = this.refs.stepthree.state.remarkinput;
        /*六个要求*/
        let dataSource_require = this.refs.stepthree.state.dataSource_require;
        let qualityAsk = dataSource_require[0].content;
        let packageAsk = dataSource_require[1].content;
        let logisticsAsk = dataSource_require[2].content;
        let payMode = dataSource_require[3].content;
        let dutyBreak = dataSource_require[4].content;
        let checkAsk = dataSource_require[5].content;
        /*制衣厂录入成衣订单 或 点击修改-发送第一、二步骤的数据*/
        let request_obj = {};
        if(this.fromEdit == "entry"){
            /*制衣厂录入成衣订单-自己是partB*/
            request_obj = {
                account:this.account.toFixed(0),
                traderName: this.traderName_three,
                signedContract:this.signedContract_three,
                parentId:this.parentId_three,
                makeType: this.makeType_three,
                createUser:createUser,
                enId:partA,
                payAccount:0,
                orderType:this.ordertype_num,
                partB:partA,
                partBName:partAName,
                partBAddress:address,
                partBUserId:createUser,
                partBPhone: phone,
                partBUserName:partAUserName,
                rmark:remark,
                contractUrl1:instructions[0]||'',
                contractUrl2:instructions[1]||'',
                contractUrl3:instructions[2]||'',
                contractUrl4:instructions[3]||'',
                contractUrl5:instructions[4]||'',
                // traderName:traderName,
                // traderId:traderId,
                // traderUser:traderUser,
                oid:this.state.oid,
                isCreate:"true",
                enquiryId:this.state.enquiryId,
                qualityAsk:qualityAsk,
                packageAsk:packageAsk,
                logisticsAsk:logisticsAsk,
                payMode:payMode,
                dutyBreak:dutyBreak,
                checkAsk:checkAsk,
                goodsInfo:this.goodssty,
                deliverRequest:this.stests,
                orderClassify:"1",
            };
        }else if(this.fromEdit == "modify"){
            /*点击修改*/
            request_obj = {
                account:this.account.toFixed(0),
                traderName: this.traderName_three,
                parentId: this.parentId_three,
                makeType: this.makeType_three,
                createUser:createUser,
                enId:partA,
                payAccount:0,
                orderType:this.ordertype_num,
                partA:partA,
                partAName:partAName,
                partAAddress:address,
                partAUserId:createUser,
                partAPhone: phone,
                partAUserName:partAUserName,
                rmark:remark,
                contractUrl1:instructions[0]||'',
                contractUrl2:instructions[1]||'',
                contractUrl3:instructions[2]||'',
                contractUrl4:instructions[3]||'',
                contractUrl5:instructions[4]||'',
                // traderName:traderName,
                // traderId:traderId,
                // traderUser:traderUser,
                oid:this.state.oid,
                isCreate:"true",
                // enquiryId:this.state.enquiryId,
                qualityAsk:qualityAsk,
                packageAsk:packageAsk,
                logisticsAsk:logisticsAsk,
                payMode:payMode,
                dutyBreak:dutyBreak,
                checkAsk:checkAsk,
                goodsInfo:this.goodssty,
                deliverRequest:this.stests,
            };
        }else {
            /*正常第三步请求*/
            request_obj = {
                payAccount:0,
                orderType:this.ordertype_num,
                partA:partA,
                partAName:partAName,
                partAAddress:address,
                partAUserId:createUser,
                partAUserName:partAUserName,
                rmark:remark,
                contractUrl1:instructions[0]||'',
                contractUrl2:instructions[1]||'',
                contractUrl3:instructions[2]||'',
                contractUrl4:instructions[3]||'',
                contractUrl5:instructions[4]||'',
                // traderName:traderName,
                // traderId:traderId,
                // traderUser:traderUser,
                oid:this.state.oid,
                isCreate:"true",
                enquiryId:this.state.enquiryId,
                qualityAsk:qualityAsk,
                packageAsk:packageAsk,
                logisticsAsk:logisticsAsk,
                payMode:payMode,
                dutyBreak:dutyBreak,
                checkAsk:checkAsk,
            };
        }

        Relay.Store.commitUpdate(
            new SaveOrderMutation(request_obj),
            {
                onFailure: () => {
                    message.error('创建失败');
                },
                onSuccess: (response) => {
                    let errorCode = response.saveOrder.saveOrder.errorCode;
                    let value = response.saveOrder.saveOrder.value;
                    let order = response.saveOrder.saveOrder.order;
                    let otherOrder = response.saveOrder.saveOrder.otherOrder;
                    if(errorCode == 0){
                        if(this.fromEdit == "entry"){
                            /*成衣订单录入-取otherOrder*/
                            message.success('创建成功');
                            EventManager.emitter('jumptab',"entry");
                            hashHistory.push({pathname:'/ordersaleyes/',state:{
                                'oid':otherOrder.oid,
                                'orderType':otherOrder.orderType,
                            }});
                        }else if (this.fromEdit == 'modify') {
                            message.success('修改成功');
                            // console.log(this.addpartBItem);
                            hashHistory.push({pathname:'/publishOrder/',state:{
                                'enterpriseId':this.enterpriseId,
                                'entype':this.entype,
                                'ordertype_num':this.ordertype_num,
                                'oid':order.oid,
                                'orderType':order.orderType,
                                'account':order.account,
                                'enquiryId': order.enquiryId,
                                // 'addpartBItem': this.addpartBItem,
                            }});
                        } else {
                            message.success('创建成功');
                            hashHistory.push({pathname:'/publishOrder/',state:{
                                'enterpriseId':this.enterpriseId,
                                'entype':this.entype,
                                'ordertype_num':this.ordertype_num,
                                'oid':order.oid,
                                'orderType':order.orderType,
                                'account':order.account,
                                'enquiryId': order.enquiryId
                            }});
                        }
                    }else{
                        message.warning(value)
                    }
                }
            }
        )
    }

    /*点击下一步*/
    creatorder(){
        if(this.state.orderstep ==0){
            this.StepOne();
        }else if(this.state.orderstep ==1){
            this.StepTwo();
        }else if(this.state.orderstep ==2){
            this.StepThree();
        }
    }


   //从excel导入modal显示
    _ToLeadExcel(){
        this.refs.tolead.setState({
            visible:true
        });
    }
    //从excel导入
    toLeadExcel(orders){
        this.refs.stepone.toLeadExcel(orders);
    }

    //从商品库导入
    ToLeadExcel(){
        this.refs.tolead.setState({
            visible:true
        });
    }

    //显示导入面料modal
    showaddMateriaModal(name){
        let parentId = this.refs.stepone.state.parentId;
        if(parentId==''){
            message.config({
                top: 30,
            })
            message.info('请选择上游订单');
            return;
        }
        // console.warn(parentId)
        this.refs.addmateria.setState({
            visible:true,
            orderId:parentId,
            name:name
        },()=>{
            this.refs.addmateria.requireData(name);
        });
    }




    //添加步骤123
    addStepOne(){
        if(this.state.orderstep==0){
            switch(this.state.name){
                case 'createordergms':
                    return  <CreactStepOneGms ToLeadExcel = {this.ToLeadExcel.bind(this)}
                                              ShowLibrary = {this.ShowLibrary.bind(this)}
                                              addModalfromlist = {this.addModalfromlist.bind(this)}
                                              showimgmodal = {this.showimgmodal.bind(this)}
                                              ref={'stepone'} key={ReactKey.key}/>
                case 'createorderraw':
                    return  <CreactStepOneRaw ToLeadExcel = {this.ToLeadExcel.bind(this)}
                                              ShowLibrary = {this.ShowLibrary.bind(this)}
                                              addModalfromlist = {this.addModalfromlist.bind(this)}
                                              showimgmodal = {this.showimgmodal.bind(this)}
                                              showaddMateriaModal = {this.showaddMateriaModal.bind(this)}
                                              ref={'stepone'} key={ReactKey.key}/>
                case 'createordercloth':
                    return  <CreactStepOneCloth ToLeadExcel = {this.ToLeadExcel.bind(this)}
                                              ShowLibrary = {this.ShowLibrary.bind(this)}
                                              addModalfromlist = {this.addModalfromlist.bind(this)}
                                              showimgmodal = {this.showimgmodal.bind(this)}
                                              showaddMateriaModal = {this.showaddMateriaModal.bind(this)}
                                              ref={'stepone'} key={ReactKey.key}/>
                case 'createorderyarn':
                    return  <CreactStepOneYarn ToLeadExcel = {this.ToLeadExcel.bind(this)}
                                                ShowLibrary = {this.ShowLibrary.bind(this)}
                                                addModalfromlist = {this.addModalfromlist.bind(this)}
                                                showimgmodal = {this.showimgmodal.bind(this)}
                                                ref={'stepone'} key={ReactKey.key}/>
                case 'createorderprint':
                    return  <CreactStepOnePrint ToLeadExcel = {this.ToLeadExcel.bind(this)}
                                               ShowLibrary = {this.ShowLibrary.bind(this)}
                                               addModalfromlist = {this.addModalfromlist.bind(this)}
                                               showimgmodal = {this.showimgmodal.bind(this)}
                                               ref={'stepone'} key={ReactKey.key}/>
                case 'entryordergms':
                    return  <CreactStepOneGms ToLeadExcel = {this.ToLeadExcel.bind(this)}
                                              ShowLibrary = {this.ShowLibrary.bind(this)}
                                              addModalfromlist = {this.addModalfromlist.bind(this)}
                                              showimgmodal = {this.showimgmodal.bind(this)}
                                              fromEdit={this.fromEdit}
                                              ref={'stepone'} key={ReactKey.key}/>
            }
        }else if(this.state.orderstep==1){
            return <CreatOrderTwo
                ref={'steptwo'}
                goodsremark={this.goodsremark}
                fromEdit={this.fromEdit}
                key={ReactKey.key}
                order_type={this.state.name}
            />
        }else if(this.state.orderstep==2){
            return <CreatOrderThree
                ispartA={this.ispartA}
                enterpriseId={this.enterpriseId}
                ref={'stepthree'}
                addinstructions = {this.addinstructions.bind(this)}
                fromEdit={this.fromEdit}
                parentId={this.parentId}
                rmark={this.rmark}
                instructions={this.instructions}
                traderName={this.traderName}
                traderUser={this.traderUser}
                traderId={this.traderId}
                dataSource_require={this.dataSource_require}
                key={ReactKey.key}
            />
        }

    }

    render() {
        let text = "";
        if(this.state.orderstep ==2){
            if(this.fromEdit == "modify"){
                text = "修改订单"
            }else {
                text = "创建订单"
            }
        }else {
            text = "下一步"
        }
        return (
            <div className="orderdetail_box">
                <div className="create_order_steps_div">
                    <Steps current={this.state.orderstep}>
                        <Step title="商品明细" />
                        <Step title="交货要求" />
                        <Step title="其他信息" />
                    </Steps>
                </div>

                <div className="create_order_main_box">
                    <div
                        style={{minHeight:500,borderRadius:"5px",position:"relative",paddingBottom:"30px"}}>
                        {
                            this.addStepOne()
                        }

                        <div style={{textAlign:'center',marginTop:40}}>
                            <Button  onClick={this.creatorder.bind(this,this.imageUrl,this.state.index)}>{text}</Button>
                        </div>
                        <div className="order_main_creat_div"></div>
                    </div>
                </div>

                <AddExistStyleModal ref={'addesm'} ordertype_num={this.ordertype_num} addModalfromlist={this.addModalfromlist.bind(this)} key={ReactKey.key}/>
                <DetailUploadModal ref={'deup'} addpact={this.addpact.bind(this)} mid={'creat'}/>
                <ToLeadExcelModal ref = {'tolead'} mid={'tolead'} toLeadExcel={this.toLeadExcel.bind(this)} type = {this.ordertype_num}/>
                <CalendarModal ref={'calendar'}/>
                <AddImgModal ref={'addimg'} setgoodsimg={this.setgoodsimg.bind(this)} key={ReactKey.key}/>
                <AddMaterialModal ref={'addmateria'} key={ReactKey.key} toLeadExcel={this.toLeadExcel.bind(this)}/>
            </div>
        )
    }
}
